package com.vvvtimes.utils;


import cn.hutool.core.codec.Base64Decoder;
import cn.hutool.core.codec.Base64Encoder;

import java.nio.charset.StandardCharsets;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;

/*
 * 加密解密工具类
 */
public class AESUtil {

    /**
     * 加密变量
     */
    private final static String PASSWORD = "46EBA233F5204195B110A447305187965";

    //原方法 case.IllIlIl11I1l1lI11
    public static String encrypt(String data) {
        byte[] bytesEncrypt = bytesEncrypt(data, PASSWORD);
        String stringEncrypt = bytesToString(bytesEncrypt);
        String base64Encrypt = base64Encode(stringEncrypt);
        return base64Encrypt;
    }

    //原方法 case.lIIlIlllIIIIIl11
    public static String decrypt(String data) {
        try {
            String decodeString = base64Decoder(data);
            byte[] bytes = stringToBytes(decodeString);
            byte[] bytesDecrypt = bytesDecrypt(bytes, PASSWORD);
            return new String(bytesDecrypt);
        } catch (Exception var4) {
            return null;
        }
    }

    private static String base64Encode(String string) {
        Base64Encoder base64Encoder = new Base64Encoder();
        String result = string;
        if (string != null && string.length() > 0) {
            try {
                byte[] bytes = string.getBytes(StandardCharsets.UTF_8);
                result = Base64Encoder.encode(bytes);
            } catch (Exception var4) {
                var4.printStackTrace();
            }
        }

        return result.replaceAll("\r\n", "").replaceAll("\r", "").replaceAll("\n", "");
    }

    private static String base64Decoder(String var0) {
        return Base64Decoder.decodeStr(var0);
    }

    private static byte[] bytesEncrypt(String data, String password) {
        try {
            KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
            SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
            secureRandom.setSeed(password.getBytes("UTF-8"));
            keyGenerator.init(128, secureRandom);
            SecretKey secretKey = keyGenerator.generateKey();
            byte[] secretKeyEncoded = secretKey.getEncoded();
            SecretKeySpec var6 = new SecretKeySpec(secretKeyEncoded, "AES");
            Cipher cipher = Cipher.getInstance("AES");
            byte[] var8 = data.getBytes("utf-8");
            cipher.init(1, var6);
            byte[] var9 = cipher.doFinal(var8);
            return var9;
        } catch (Exception var10) {
            return null;
        }
    }

    private static byte[] bytesDecrypt(byte[] data, String password) {
        try {
            KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
            SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG");
            secureRandom.setSeed(password.getBytes("UTF-8"));
            keyGenerator.init(128, secureRandom);
            SecretKey secretKey = keyGenerator.generateKey();
            byte[] secretKeyEncoded = secretKey.getEncoded();
            SecretKeySpec secretKeySpec = new SecretKeySpec(secretKeyEncoded, "AES");
            Cipher cipher = Cipher.getInstance("AES");
            cipher.init(2, secretKeySpec);
            byte[] var8 = cipher.doFinal(data);
            return var8;
        } catch (Exception var9) {
            return null;
        }
    }

    private static String bytesToString(byte[] bytes) {
        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < bytes.length; ++i) {
            String hexString = Integer.toHexString(bytes[i] & 255);
            if (hexString.length() == 1) {
                hexString = "0" + hexString;
            }
            stringBuffer.append(hexString.toUpperCase());
        }
        return stringBuffer.toString();
    }

    private static byte[] stringToBytes(String string) {
        if (string.length() < 1) {
            return null;
        } else {
            byte[] result = new byte[string.length() / 2];

            for (int i = 0; i < string.length() / 2; ++i) {
                int high = Integer.parseInt(string.substring(i * 2, i * 2 + 1), 16);
                int low = Integer.parseInt(string.substring(i * 2 + 1, i * 2 + 2), 16);
                result[i] = (byte) (high * 16 + low);
            }
            return result;
        }
    }

    public static void main(String[] args) {
        //查找  Activate plugin -->AES 密文  NDU1QTVEMDQ1MDhCOEIzMDY5RTE3NzUwNzhCODFCREY=  -->找到 ll1lIlIlIIl1I1ll11I1.ll1lIlIlIIl1I1ll11I1(Project var0) -->找到激活判断 if(I1lIl1lI1l1I1IlIIll.IIl1lIl1111IlIlI1()) 修改返回
        //查找  Activate plugin -->AES 密文  NDU1QTVEMDQ1MDhCOEIzMDY5RTE3NzUwNzhCODFCREY=  -->找到  ll1lIlIlIIl1I1ll11I1.ll1lIlIlIIl1I1ll11I1(Project var0) -->找到激活判断  if(licence.lIIlIlllIIIIIl11()) 修改返回
        //ActivatePlugin=Activate Plugin
        //ActivatePluginNeed=Please activate the plugin first.

        System.out.println(AESUtil.encrypt("Activate plugin"));
        //NDU1QTVEMDQ1MDhCOEIzMDY5RTE3NzUwNzhCODFCREY=
        String a1 = AESUtil.decrypt("NThEMTFCNDc0REVDMEI4QTFDMTUzMEIzQUIwRjUwNDM=");
        //FastRequest
        System.out.println(a1);
        String  a2= AESUtil.decrypt("ASJH4IfHSDJHHdJAJS8DHs8ah");
        //null
        System.out.println(a2);
        String  a3_zh = AESUtil.decrypt("MDdGRjM3ODExNTU3Mzg4ODU0OTdGNzM3MDIwREQwQUU=");
        //激活
        System.out.println(a3_zh);
        String  a3= AESUtil.decrypt("NDU1QTVEMDQ1MDhCOEIzMDY5RTE3NzUwNzhCODFCREY=");
        //Activate plugin
        System.out.println(a3);

        String  a4_zh = AESUtil.decrypt("N0NGNDIxNjMzRkE3M0RDRDQ0MTZBODYyMThGN0E2NDlBNkIwMkRBMUQ5Q0U2OURBMEVBMzdFMjFBMjQxMkZGOQ==");
        //请先激活插件
        System.out.println(a4_zh);
        String  a4 = AESUtil.decrypt("RTZCRjEyNUEzNzA3Mzg0MDQzMzU3OTFFMzk2RTQ1MDM0NTM1NTI3OTQ2ODhFOTM3RUZFODk1RDk3NkM3RTIzODQzOUNFMjI3M0EzMDM1RjMwQUY0OTRGQzNCOUU3QjhG");
        //Please activate the plugin first.
        System.out.println(a4);

        String  a5= AESUtil.decrypt("RTZCRjEyNUEzNzA3Mzg0MDQzMzU3OTFFMzk2RTQ1MDM0NTM1NTI3OTQ2ODhFOTM3RUZFODk1RDk3NkM3RTIzOENGNUQxNjI5OTZDREE3OTM4NDY4Q0YzRThGRTU5M0E0");
        //Please activate the plugin first.
        System.out.println(a5);

        String  a6_zh = AESUtil.decrypt("QjNFRTE4RUZDREJENjAzMEYwNjcxRUIyQTJFMjg0MEI2ODAwNzM5ODhGNkVCNDUzRTMzMEQ5NkI5Qzc3NjUwRA==");
        System.out.println(a6_zh);
        String  a6= AESUtil.decrypt("RTZCRjEyNUEzNzA3Mzg0MDQzMzU3OTFFMzk2RTQ1MDNCNzFFRkI5MkI0Q0RFNzM3MDNBRTM2MURGODZDN0U1RTUwOEUyNUEyNDJBODAxNzJDOTlBQTU4MUM0NDVDNUE3");
        //Please activate or start trial plugin first
        System.out.println(a6);

        String  a7= AESUtil.decrypt("NkRCOUM0OEQzM0FCMERFN0FCMDU4MUM2MDVBMENDRjg=");
        //Document
        System.out.println(a7);

        String  a8= AESUtil.decrypt("QUM5REY1Q0JGQjQ5QTU4NDg3NTdDNDk1REE0MkEyOTI=");
        // /guide/buy.html
        System.out.println(a8);

        String  a9_zh= AESUtil.decrypt("ODY5OTk2MUZBN0JFREQzNjE4MjE4NDI2OEQyMjg2MDBGODNERjFERERBREMwQzNGQTU5NEZCNTlBQjJFOEFCMUQzOTBFNDg4RUM2RkE5QTEzNTgzOTNGMzMzMDg1NTUzMjdGNDFFMDk1RUY3RDREREZBQThGOUQxOUFCOTcxRjlEODdEOTkzOTAxNzE0RkRENjBDMUEwNzFDODY4QURCRTk0OUM1M0IxNjNEQUQzRDRFNzhBMEI1MkE4NDM0OTAwNDlDNjI5OEMwQkRCQzFBMjRGNzM2QUY0QzlEQkYyNTg=");
        //非法激活,请前往支付页面购买,并移除现有license后使用官方license激活,最后重启IDEA
        System.out.println(a9_zh);
        String  a9= AESUtil.decrypt("MEMzQkUwNTgzMjcxNDIyNERERURFMTZBMzcyOTFDNEUxQ0QxOEYzREE0ODIyNDkxM0NDNEQyMTZERjMxOTVERTYzNkU1RTU5QjMyNzNCMEFBRkFFOEYyMkE0RDYwRThBMkIxMTQwQjczODQ4MzYwMEVGQkM3RTFGNDNFQjU3QkY3RDMxRDA3MUY3NUREMzJENjcwQjEzM0VBMjAxQjI2MTNGNzhERkNDNzMwMkY0NjQzMkRDNzU2NTJBOEQzNEI5QTA3N0Y3Rjg2QTQ4OUM3OUZFMDE5ODI2RUMzQTAzQ0EzQ0IyRUI3ODY2MzE0MDRBMTA3NkVBMzQ2NTQ2MjJGRkY1QjBFQTM3MzZGRkQ4QTRGMDZEOTFCNDE3RjdEMkQzRDRGNkQ3NDlDMTEwQTAwMjBDQjcxQ0FFRDhBMDM3QzA=");
        //Invalid activation, please go to the payment page to purchase, delete the existing license and activate with the official license, finally restart IDEA
        System.out.println(a9);

        String  a10_zh= AESUtil.decrypt("OEM4OTJGRkZCQkUxRDEwQTNFOUYwRTNFNkZGOENDNzY=");
        //购买
        System.out.println(a10_zh);
        String  a10= AESUtil.decrypt("NjkxNkMzNUQ4MDI5RkIzNzQyQzcyOUEwNzk5RjRFNjA=");
        //Purchase
        System.out.println(a10);

        String  a11_zh = AESUtil.decrypt("QkMzMkM1QkJBOThDNDQ5ODdDMkZBM0VEMzIyNjVGNjg=");
        //教程
        System.out.println(a11_zh);
        String  a11 = AESUtil.decrypt("ODgxNEJFMkYzNDY2N0NBMDVDNzUyNTFFNTBBRkM3Qjk=");
        //tutorial
        System.out.println(a11);

        String  a12 = AESUtil.decrypt("MTg3RjMzRDY3RDJGQTg5QkM5Qjg4M0E3NEZCNUVBOEQ2RkFDNEE1NTlFOTc1NUM3MzkxQ0JDRkFCRkQxRkQ1NEEyN0RFMzU5NzNENjJFNkYyMzlEQjMzMjJGQzkzMjY3MDkzMkY5REUzQ0E4OENEOTc0MUJBOUFFMUZCRjYzQURDMDA1QUNCQTdFREMwNTNDQURCREU0NjczRjRFOEIxNTlDOEY2ODI0NUIyODlFNUU1QkIzMkI2NUNDRjZBQjJC");
        //https://plugins.jetbrains.com/plugin/16988-restful-fast-request--api-buddy/pricing
        System.out.println(a12);

    }
}
